package com.mijie.homi.test;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

public class NatureNode {

	private String name;
	private boolean isLeaf;
	private boolean hasChild = false;
	private List<NatureNode> childs;
	private NatureNode prev;
	
	NatureNode(String name){
		this.name = name;
	}
	
	public String name(){
		return name;
	}
	
	public boolean isLeaf(){
		return this.isLeaf;
	}
	
	public void isLeaf(boolean isLeaf){
		this.isLeaf = isLeaf;
	}
	
	public void addChild(NatureNode node){
		if(childs==null){
			childs = new ArrayList<NatureNode>();
			hasChild = true;
		}
		childs.add(node);
	}
	
	public NatureNode findChild(String name){
		if(hasChild){
			for(int i=0;i<childs.size();i++){
				if(childs.get(i).name.equals(name)) 
					return childs.get(i);
			}
		}
		return null;
	}
	
	public boolean hasChild(){
		return this.hasChild;
	}
	
	
	public void prev(NatureNode prev){
		this.prev = prev;
	}
	
	public NatureNode prev(){
		return prev;
	}
	

	@Override
	public int hashCode() {
		int hash = 0;
		for(char c : name.toCharArray()){
			hash += c;
		}
		return hash;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if(obj!=null){
			NatureNode o = (NatureNode)obj;
			if(o.name!=null && name.equals(o.name)) 
				return true;
		}
		return false;
	}
	
	
}
